package com.jxaummd.mushroom.main.common.presenter;

import android.text.TextUtils;

import com.blankj.utilcode.util.ToastUtils;
import com.blankj.utilcode.util.Utils;
import com.jxaummd.mushroom.R;
import com.jxaummd.mushroom.core.base.data.CommonBackModel;
import com.jxaummd.mushroom.core.base.data.DataSource;
import com.jxaummd.mushroom.core.base.presenter.BasePresenter;
import com.jxaummd.mushroom.main.common.contract.ForgetPasswordSendCodeContract;
import com.jxaummd.mushroom.main.common.data.SendCodeData;

public class ForgetPasswordSendCodePresenter extends BasePresenter<ForgetPasswordSendCodeContract.View>
        implements  ForgetPasswordSendCodeContract.Presenter, DataSource.Callback<CommonBackModel> {

    public ForgetPasswordSendCodePresenter(ForgetPasswordSendCodeContract.View view) {
        super(view);
    }

    @Override
    public void sendCode(String phoneNumber) {
        if(TextUtils.isEmpty(phoneNumber)||phoneNumber.length()<11){
            ToastUtils.showShort(Utils.getApp().getResources().getString(R.string.common_signup_phonenumber_nocooect));
        }else {
            //发送验证码
            SendCodeData.sendForgetPasswordCode(phoneNumber,this);
        }
    }

    @Override
    public void onDataNotAvailable(int strRes) {

    }

    @Override
    public void onDataLoaded(CommonBackModel commonBackModel) {
            ToastUtils.showShort(commonBackModel.getMessage());
            if (commonBackModel.getStatus()==200){
                getView().sendSuccess();
            }

    }
}
